package schema

import (
	"time"

	"lianzi_gos/pkg/util"
)

// 意向客户表
type Buyer struct {
	ID          string    `json:"id" gorm:"size:20;primarykey;"`   // Unique ID
	UID         string    `json:"uid" gorm:"size:32;index"`        // 员工ID
	Name        string    `json:"name" gorm:"size:32;index"`       // 客户名称
	Phone       string    `json:"phone" gorm:"size:20;index"`      // 电话
	StoreName   string    `json:"store_name" gorm:"size:50;index"` // 门店名称
	Address     string    `json:"address" gorm:"size:500"`         // 门店地址
	Description string    `json:"description" gorm:"size:1024"`    // Details about dictionary
	Status      string    `json:"status" gorm:"size:20;index"`     // Status of dictionary (disabled, enabled)
	CreatedAt   time.Time `json:"created_at" gorm:"index;"`        // Create time
	UpdatedAt   time.Time `json:"updated_at" gorm:"index;"`        // Update time
}

// Defining the query parameters for the `Buyer` struct.
type BuyerQueryParam struct {
	util.PaginationParam
	UID           string `form:"-"`          // 员工ID
	LikeName      string `form:"name"`       // 客户名称
	LikePhone     string `form:"phone"`      // 电话
	Uid           string `form:"uid"`        // uid 存在 根据uid 查员工
	LikeStoreName string `form:"store_name"` // 门店名称
	Source        int64  `form:"source"`     // 来源
	Status        string `form:"status"`     // Status of dictionary (disabled, enabled)
}

// Defining the query options for the `Buyer` struct.
type BuyerQueryOptions struct {
	util.QueryOptions
}

// Defining the query result for the `Buyer` struct.
type BuyerQueryResult struct {
	Data       Buyers
	PageResult *util.PaginationResult
}

// Defining the slice of `Buyer` struct.
type Buyers []*Buyer

// Defining the data structure for creating a `Buyer` struct.
type BuyerForm struct {
	Name        string `json:"name" binding:"required,max=32"`       // 客户名称
	Phone       string `json:"phone" binding:"required,max=20"`      // 电话
	StoreName   string `json:"store_name" binding:"required,max=50"` // 门店名称
	Address     string `json:"address"`                              // 门店地址
	Description string `json:"description"`                          // Details about dictionary
}

// A validation function for the `BuyerForm` struct.
func (a *BuyerForm) Validate() error {
	return nil
}

// Convert `BuyerForm` to `Buyer` object.
func (a *BuyerForm) FillTo(buyer *Buyer) error {
	buyer.Name = a.Name
	buyer.Phone = a.Phone
	buyer.StoreName = a.StoreName
	buyer.Address = a.Address
	buyer.Description = a.Description
	buyer.Status = "enabled"
	return nil
}
